Component({
  properties: {
    // 控制弹窗的显示和隐藏
    isVisible: {
      type: Boolean,
      value: false
    },
  },
  data: {
    initAvatarUrl: 'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132',
    avatarUrl: '',
    nickname: '',
  },
  methods: {
    onChooseAvatar(e) {
      this.setData({
        avatarUrl: e.detail.avatarUrl
      })
    },
    // 关闭弹窗
    closeDialog() {
      this.setData({
        isVisible: false
      });
      this.triggerEvent('close'); // 触发关闭事件
    },

    // 表单提交
    handleSubmit(e) {

      if (this.data.avatarUrl == '') {
        wx.showToast({
          title: '头像不能为空',
          icon: 'error',
        })
        return
      }
      if (e.detail.value.nickname == '') {
        wx.showToast({
          title: '昵称不能为空',
          icon: 'error',
        })
        return
      }
      let nickname= e.detail.value.nickname
      let avatarUrl= this.data.avatarUrl
      this.triggerEvent('submit', {nickname ,avatarUrl}); // 触发提交事件，将数据传递给父页面
      this.closeDialog(); // 提交后关闭弹窗
    }
  }
});